from django.db import models

# Create your models here.
class BaseModel(models.Model):
    created_time = models.DateTimeField(auto_now_add=True)
    updated_time = models.DateTimeField(auto_now=True)

# 部门表
class Department(BaseModel):
    name = models.CharField(max_length=30)

    class Meta:
        db_table = 'tb_department'

    def __str__(self):
        return self.name

# 职责表
class Duty(BaseModel):
    name = models.CharField(max_length=30, verbose_name='职务名称')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'tb_duty'
# 员工表
class Staff(models.Model):  # 不能也继承BaseModel，会冲突
    SEX_CHOICE = (
        (1, '男'),
        (2, '女')
    )

    name = models.CharField(max_length=30, verbose_name='姓名')
    sex = models.IntegerField(choices=SEX_CHOICE, default=1, verbose_name='性别')
    phone = models.CharField(max_length=11, verbose_name='手机号')
    email = models.EmailField(max_length=60, verbose_name='邮箱')
    department = models.ForeignKey(Department, on_delete=models.CASCADE)
    duty = models.ForeignKey(Duty, on_delete=models.CASCADE)
    def __str__(self):
        return self.name

    class Meta:
        db_table = 'tb_staff'

from django.utils import timezone
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
    modele = models.CharField("手机号",max_length=11)
    last_login = models.DateTimeField('上次登陆',default=timezone.now)
    def __str__(self):
        return self.username
    class Meta:
        db_table ='user'


